import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  // 共享数据
  state: {
    count: 101,
    test: 520
  },
  // 变更store中的数据，ke集中监控数据变化
  mutations: {
    add(state, val) {
      // console.log(val)
      state.count += val
    },
    jian(state, val, cc) {
      console.log(val, cc)
      state.count--
    },
    tes() {
      console.log('test')
    },
    cheng(state, val) {
      state.count += val
    }
  },
  actions: {
    yibu(aa, step) {
      setInterval(function () {
        // 只能通过commit 触发mutations中的函数修改数据
        aa.commit('cheng', step)
      }, 1)
    }
  },
  getters: {
    testget(state) {
      return state.count
    }
  }
})
